import sys


# # -2 11 -4 13 -5 -2
def find(dp, A):
    for i in range(1, len(A)):
        dp[i] = max(A[i], dp[i - 1] + A[i])


for line in sys.stdin:
    n = int(line.rstrip())
    if n == 0:
        print(0, 0, 0)
        continue
    A = list(map(int, input().split()))
    flag = False
    # 判断是否全负
    for i in A:
        if i >= 0:
            flag = True
            break
    if flag:
        dp = [0 for i in range(len(A))]
        dp[0] = max(A[0], 0)
        find(dp, A)
        m = 0
        mi = 0
        for i, v in enumerate(dp):
            if v > m:
                m = v
                mi = i
        for i in range(mi, -1, -1):
            if sum(A[i:mi+1]) == m:
                print(m, A[i], A[mi])
                continue
